package com.yu1996.article.service;

import com.yu1996.article.dao.CommentDao;
import com.yu1996.article.pojo.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;

@Service
@Transactional
public class CommentService {

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private IdWorker idWorker;

    /**
     * @param comment 评论内容
     * @return void
     * @description 添加评论
     * @date 2019/10/14 9:16
     */
    public void add(Comment comment) {
        comment.set_id(idWorker.nextId() + "");
        commentDao.save(comment);
    }

    /**
     * @param id
     * @return com.yu1996.article.pojo.Comment
     * @description 根据id查询评论
     * @date 2019/10/14 9:26
     */
    public Comment findById(String id) {
        return commentDao.findById(id).get();
    }

    /**
     * @param id
     * @return void
     * @description 删除评论
     * @date 2019/10/14 9:31
     */
    public void delete(String id) {
        commentDao.deleteById(id);
    }

}
